
*! lss, lisheng2@foxmail.com, 2019-1-14
*! 1.0 2019.1.14
*cap program drop wl
program define wl //输入项   
version 14.0
syntax varlist(numeric), Power(integer)  				//输入1表示正向指标，-1表示负向指标            

*无量纲化处理
if `power'==1{
 foreach v of varlist `varlist'{
   egen `v'_max=max(`v')
   egen `v'_min=min(`v')
   gen  `v'_m_n=`v'_max-`v'_min
   gen  `v'_fenzi=`v'-`v'_min
   qui replace `v'=`v'_fenzi/`v'_m_n
   drop `v'_*
  
 }
  dis in red  "正向指标无量纲化完毕" 
} 
 else if `power'==-1{
	 foreach v of varlist `varlist'{
	 egen `v'_min=min(`v')
	 egen `v'_max=max(`v') 
	 gen  `v'_m_n=`v'_max-`v'_min
	 gen  `v'_fenzi=`v'_max-`v'
	 qui replace  `v'=`v'_fenzi/`v'_m_n
	 drop `v'_*
	 
}
dis in red  "负向指标无量纲化完毕" 
}
 else {
 dis in red "输入有误"
 }
 
end
*---------------- wl.ado -------------over---


